package com.chen.controller;

import com.chen.service.SysUserService;
import com.chen.vo.ErrorCode;
import com.chen.vo.Result;
import com.chen.vo.param.SysUserParam;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:chenao
 * @DATE:2022/3/10 22:32
 */
@RestController
@RequestMapping("sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 系统用户管理列表
     * @param param
     * @return
     */
    @PostMapping("list")
    public Result listSysUser (@RequestBody SysUserParam param){
        return sysUserService.listSysUser(param);
    }

    /**
     * 添加(编辑)用户信息
     * @param param
     * @return
     */
    @PostMapping("save")
    public Result saveSysUser(@RequestBody SysUserParam param){
        return sysUserService.saveSysUser(param);
    }

    /**
     * 重置用户密码
     * @param param
     * @return
     */
    @PostMapping("reset")
    public Result resetPwd(@RequestBody SysUserParam param){
        return sysUserService.resetSysUserPwd(param);
    }

    /**
     * 修改用户账号是否可用，1代表可用，0代表不可用，即不能登录
     * @param param
     * @return
     */
    @PostMapping("status")
    public Result updateStatus(@RequestBody SysUserParam param){
        return sysUserService.updateSysUserStatus(param);
    }

    /**
     * 更换系统用户角色
     * @param param 内含角色值，如system代表系统管理员
     * @return
     */
    @PostMapping("role")
    public Result updateRole(@RequestBody SysUserParam param){
        return sysUserService.updateSysUserRole(param);
    }

    /**
     * 删除
     * @param param
     * @return
     */
    @PostMapping("delete")
    public Result deleteUser(@RequestBody SysUserParam param){
        return sysUserService.deleteSysUser(param.getId());
    }

    /**
     * 修改个人密码
     * @param param
     * @return
     */
    @PostMapping("personal/updatepwd")
    public Result updatePwd(@RequestBody SysUserParam param){
        return sysUserService.updatePwd(param);
    }

    /**
     * 修改个人信息
     * @param param
     * @return
     */
    @PostMapping("personal/save")
    public Result updatePersonal(@RequestBody SysUserParam param){
        return sysUserService.personalUpdate(param);
    }

}
